#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 110;
int a[N];

void solve() {
	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		int x;
		string s;
		cin >> x >> s;
		for (int j = s.size() - 1; j >= 0; j--) {
			if (s[j] == 'U') {
				a[i]--;
				if (a[i] < 0) a[i] = 9;
			}else {
				a[i]++;
				if (a[i] > 9) a[i] = 0;
			}
		}
	}
	for (int i = 1; i <= n; i++) cout << a[i] << " ";
	cout << endl;
}

signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T; cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}